<template>
	<view class="order-details">
		<view class="navbar flex-as" :style="{
        'background-image': navBg(formData.orderStatus),
      }">
			<view style="padding-top: 7rpx">
				<u-icon name="clock" color="#ffffff" size="20"></u-icon>
			</view>

			<view class="tip">
				<view>{{ dict.data.order_status[formData.orderStatus] }}</view>
				<view>{{ navTip(formData.orderStatus) }}</view>
			</view>
		</view>
		<view class="container">
			<view class="item-title flex-ac flex-jb">
				<view>订单信息</view>
			</view>
			<view class="form">
				<view class="form-item l-border-bottom">
					<view>订单编号：</view>
					<view>{{ formData.orderCode }}</view>
				</view>
				<view class="form-item l-border-bottom">
					<view>申请人：</view>
					<view>{{ userInfo.nickName }}</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.createTime">
					<view>申请时间：</view>
					<view>{{ formData.createTime }}</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.createTime">
					<view>备注：</view>
					<view>{{ formData.remark }}</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.recyclingCompanyName">
					<view>收运单位：</view>
					<view>{{ formData.recyclingCompanyName }}
					</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.orderStatus != 0 && formData.orderStatus != 3">
					<view>收运人：</view>
					<view>{{ formData.recyclerName || ''}}</view>
				</view>
				<view class="form-item l-border-bottom"  v-if="formData.orderStatus != 0  && formData.orderStatus != 3">
					<view>收运司机：</view>
					<view>{{ formData.driverName || ''}}</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.licensePlateNumber">
					<view>收运车牌号：</view>
					<view>{{ formData.licensePlateNumber || '' }}</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.weight && formData.orderStatus == 2 && formData.serviceType == 1">
					<view>收运重量：</view>
					<view>{{ formData.weight }}</view>
				</view>
				<view class="form-item l-border-bottom" v-if="formData.dispatchTime">
					<view>{{formData.serviceType == 1 ? "收运时间" : "清掏时间"}}：</view>
					<view>{{ formData.dispatchTime }}</view>
				</view>
				<!-- <view class="form-item l-border-bottom" v-if="formData.address.detailedAddress">
					<view>{{formData.serviceType == 1 ? "收运时间" : "清掏时间"}}：</view>
					<view>{{ formData.address.detailedAddress }}</view>
				</view> -->
			</view>
			
			<view class="item-title flex-ac flex-jb" v-if="formData.oilList && formData.serviceType == 1">
				<view>油品信息</view>
			</view>
			<view class="form form-youpin">
				<view class="form-item l-border-bottom" v-for="(item,index) in formData.oilList">
					<view>油品名称：{{item.oilName}}</view>
					<view class="label">
						<view>{{item.categoryName}}</view>
						<view>{{item.barrelsNumber}}桶</view>
						<view>{{item.weight}}kg</view>
					</view>
				</view>
			</view>

			<template v-if="formData.orderStatus == 0">
				<view class="submit-button flex-jc flex-as">
					<view class="button-light button-deep" @click="cancelOrder"> 取消申请 </view>
				</view>
			</template>
		</view>
		<template v-if="formData.orderStatus == 3">
			<view class="submit-button flex-jc flex-as">
				<view class="reapply" @click="reAppointment"> 重新申请 </view>
			</view>
		</template>
	</view>
</template>

<script>
	import {
		receiptShipmentRecordsDetails,
		cancelApplication
	} from "@/api";
	import {
		getDicts
	} from "@/utils";
	export default {
		data() {
			return {
				formData: {},
				params: {},
				dict: {},
			};
		},
		computed: {
			navTip() {
				return (state) => {
					if (state == 0) {
						return "请等待工作人员派单处理";
					}else if (state == 1) {
						return "请等待工作人员上门收运";
					} else if (state == 2) {
						return "您申请的收运已完成";
					} else if (state == 3) {
						return "您已取消当前申请";
					} else if (state == 4) {
						return "请等待工作人员上门收运";
					}
				};
			},
			navBg() {
				return (state) => {
					console.log('state',state);
					if (state == 0) {
						let img = `/static/icon_processing_bg.png`,
						imgBase64 = wx.getFileSystemManager().readFileSync(img, "base64"),
						base64Url = `data:image/png;base64,${imgBase64}`;
						return `url(${base64Url})`;
					} else if (state == 1) {
						let img = `/static/icon_processing_bg.png`,
						imgBase64 = wx.getFileSystemManager().readFileSync(img, "base64"),
						base64Url = `data:image/png;base64,${imgBase64}`;
						return `url(${base64Url})`;
					}else if (state == 2) {
						let img = `/static/icon_done_bg.png`,
						imgBase64 = wx.getFileSystemManager().readFileSync(img, "base64"),
						base64Url = `data:image/png;base64,${imgBase64}`;
						return `url(${base64Url})`;
					} else if (state == 3) {
						let img = `/static/icon_cancel_bg.png`,
						imgBase64 = wx.getFileSystemManager().readFileSync(img, "base64"),
						base64Url = `data:image/png;base64,${imgBase64}`;
						return `url(${base64Url})`;
					} else if (state == 4) {
						let img = `/static/icon_processing_bg.png`,
						imgBase64 = wx.getFileSystemManager().readFileSync(img, "base64"),
						base64Url = `data:image/png;base64,${imgBase64}`;
						return `url(${base64Url})`;
					}
				};
			},
			userInfo() {
			  return this.$store.state.userInfo;
			},
		},
		onLoad(params) {
			console.log(params);
			this.params = params;
		},
		onShow() {
			this.$store.dispatch("userInfo");		
			this.getData();
			getDicts([
				"order_status",
			]).then((data) => {
				this.dict = data;
			});

		},
		methods: {
			reAppointment() {
				this.$modal(`是否重新申请该订单？`, () => {
				  // 收油
				  if(this.formData.serviceType == '1'){
				  	this.$route({
				  		url: "/pages/apply/index",
				  		params: {
				  			id:this.formData.id,
				  		},
				  	});
				  }else{
				  	this.$route({
				  		url: "/pages/apply/clean",
				  		params: {
				  			id:this.formData.id,
				  		},
				  	});
				  }
				});
				
			},

			cancelOrder() {
				this.$modal(`是否取消该订单？`, () => {
					cancelApplication(this.formData.id).then((res) => {
						this.$toast(`取消成功`);
						// this.listData = []
						// this.queryParams.pageNum = 1
						this.getData();
					});
				});
			},

			getData() {
				receiptShipmentRecordsDetails(this.params.id).then((res) => {
					this.formData = res.data;
				});
			},
		},
	};
</script>

<style lang="less" scoped>
	.order-details {
		padding-bottom: 160rpx;

		.reapply {
			width: 80%;
			margin: 0 auto;
			margin-top: 20rpx;
			padding: 16rpx 0;
			background: linear-gradient(83deg, #48b453 0%, #2c9f79 100%);
			border-radius: 200rpx;
			font-size: 32rpx;
			font-weight: 600;
			color: #ffffff;
			text-align: center;
		}

		.navbar {
			color: #ffffff;
			padding: 40rpx 0 34rpx 32rpx;
			background-repeat: no-repeat;
			background-size: 100% 100%;

			.tip {
				margin-left: 20rpx;

				:nth-child(1) {
					font-size: 34rpx;
					box-sizing: border-box;
				}

				:nth-child(2) {
					font-size: 24rpx;
					margin-top: 6rpx;
				}
			}
		}

		.container {
			padding: 30rpx;
		}

		.submit-button {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			height: 160rpx;
			background: #ffffff;
		}

		.car-list {
			padding: 0 30rpx;
			background: #ffffff;
			border-radius: 16rpx;
			margin-bottom: 26rpx;

			.car-item {
				padding: 30rpx 0;
			}

			.car-info {
				margin-left: 30rpx;
			}

			.car-name {
				font-size: 32rpx;
				color: #000000;
				margin-bottom: 20rpx;
			}

			.car-config {
				font-size: 28rpx;

				view {
					margin-right: 20rpx;
				}
			}
		}

		.button-light,
		.button-deep {
			width: 85%;
			border-radius: 200rpx;
			padding: 16rpx 26rpx;
			margin: 20rpx 0 0 0;
			text-align: center;
		}

		.button-light {
			background: #f7f7f7;
			border: 2rpx solid #138e57;
			color: #138e57;
		}

		.button-deep {
			background: linear-gradient(83deg, #48b453 0%, #2c9f79 100%);
			color: #ffffff;
		}

		.item-title {
			padding-bottom: 20rpx;

			view:nth-child(1) {
				font-size: 30rpx;
				color: #000000;
			}

			view:nth-child(2) {
				font-size: 28rpx;
			}
		}

		.form {
			background: #ffffff;
			border-radius: 16rpx;
			padding: 0 30rpx;
			&.form-youpin{
				.form-item{
					flex-direction: column;
					view:nth-child(1) {
						color: #000;
					}
					.label{
						display: flex;
						margin-top: 10rpx;
						view{
							font-size: 24rpx;
							color: #999;
							margin-right: 10rpx;
						}
					}
				}
			}
			.form-item {
				display: flex;
				font-size: 30rpx;
				padding: 30rpx 0;
				margin-bottom: 32rpx;

				view:nth-child(1) {
					white-space: nowrap;
				}

				view:nth-child(2) {
					color: #000;
				}
			}
		}
	}
</style>